﻿namespace TestTool.GUI.Utils
{
    using System;
    using System.Collections.Generic;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using TestTool.HttpTransport.Interfaces;
    using TestTool.Proxies.Onvif;

    internal class RecordingServiceProvider : BaseServiceProvider<RecordingPortClient, RecordingPort>
    {
        public RecordingServiceProvider(string serviceAddress, int messageTimeout) : base(serviceAddress, messageTimeout)
        {
            base.EnableLogResponse = false;
        }

        public override RecordingPortClient CreateClient(Binding binding, EndpointAddress address)
        {
            return new RecordingPortClient(binding, address);
        }

        public List<GetRecordingsResponseItem> GetRecordings()
        {
            Action unsecure = null;
            List<GetRecordingsResponseItem> list = new List<GetRecordingsResponseItem>();
            GetRecordingsResponseItem[] response = new GetRecordingsResponseItem[0];
            if (base.Security == Security.None)
            {
                if (unsecure == null)
                {
                    unsecure = delegate {
                        response = this.Client.GetRecordings();
                    };
                }
                base.ConstructSecurityTolerantAction(unsecure)();
            }
            else
            {
                response = base.Client.GetRecordings();
            }
            list.AddRange(response);
            return list;
        }
    }
}

